package com.zipking.cloud.springbootmybatis.guava;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Multimap;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.redisson.misc.Hash;

import java.util.Set;

public class BiMapExample {
    public static void main(String[] args) {
        BiMap<String, Integer> biMap  = HashBiMap.create();
        // 向BiMap中添加元素
        biMap.put("One", 1);
        biMap.put("Two", 2);
        biMap.put("Three", 3);
        System.out.println("Two maps to: " + biMap.get("Two"));
// 检查BiMap中是否包含某个键
        System.out.println("Does the map contain key 'One'? " + biMap.containsKey("One"));
        // 输出: Does the map contain key 'One'? true

        // 检查BiMap中是否包含某个值
        System.out.println("Does the map contain value 2? " + biMap.containsValue(2));
        // 输出: Does the map contain value 2? true

        // 获取BiMap的键集
        Set<String> keys = biMap.keySet();
        System.out.println("Keys in the map: " + keys); // 输出: Keys in the map: [One, Two, Three]

        // 获取BiMap的值集
        Set<Integer> values = biMap.values();
        System.out.println("Values in the map: " + values);
        // 输出: Values in the map: [1, 2, 3]

        // 获取BiMap的大小
        int size = biMap.size();
        System.out.println("Size of the map: " + size);
        // 输出: Size of the map: 3

        // 尝试添加一个已存在的键（将抛出IllegalArgumentException）
        try {
            biMap.put("One", 4);
        } catch (IllegalArgumentException e) {
            System.out.println("Caught exception: " + e.getMessage());
            // 输出: Caught exception: value already present: One
        }

        // 尝试添加一个已存在的值（将抛出IllegalArgumentException）
        try {
            biMap.put("Four", 1);
        } catch (IllegalArgumentException e) {
            System.out.println("Caught exception: " + e.getMessage());
            // 输出: Caught exception: value already present: 1
        }

        // 使用forcePut方法替换现有键的值（不推荐，会破坏BiMap的双向性）
        // 不建议使用forcePut，因为它可能会使BiMap处于不一致的状态
        // biMap.forcePut("One", 4);

        // 从BiMap中移除一个键值对
        Integer removedValue = biMap.remove("Two");
        System.out.println("Removed value for key 'Two': " + removedValue);
        // 输出: Removed value for key 'Two': 2

        // 清除整个BiMap
        biMap.clear();
        System.out.println("Is the map empty after clearing? " + biMap.isEmpty());

        Multimap<String, String> multimap = ArrayListMultimap.create();
        multimap.put("csc","1");
        multimap.put("lwl","1");
        multimap.put("csc","1");
        multimap.put("lwl","one");
        System.out.println(multimap.get("csc"));
        System.out.println(multimap.get("lwl"));


    }



}
